package com.ddwl.goods.service;

import cn.hutool.core.util.StrUtil;
import com.ddwl.common.constant.BaseEnum;
import com.ddwl.common.constant.Constant;
import com.ddwl.common.util.BeanConverUtils;
import com.ddwl.goods.dao.SignActivityDao;
import com.ddwl.goods.model.SignActivity;
import com.ddwl.schema.bo.goods.SignActivityBo;
import com.ddwl.schema.vo.goods.SignActivityVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author hemiaojun
 * @Date 2020/10/19 15:09
 */
@Service
public class SignActivityService {

    @Resource
    private SignActivityDao signActivityDao;

    public SignActivityVo add(SignActivityBo bo) {
        SignActivity entity = BeanConverUtils.convertBean(bo, SignActivity.class);
        if (null == entity) {
            entity = new SignActivity();
        }
        if(StrUtil.isEmpty(entity.getName())){
            entity.setName("签到活动");
        }
        if (null == entity.getEnable()) {
            entity.setEnable(BaseEnum.StatusEnum.ENABLE.getCode());
        }
        signActivityDao.insert(entity);
        return BeanConverUtils.convertBean(entity, SignActivityVo.class);
    }

    public void enableOrDisable(SignActivityBo bo) {
        SignActivity entity = BeanConverUtils.convertBean(bo, SignActivity.class);
        signActivityDao.updateByPrimaryKeySelective(entity);
    }

    public SignActivityVo get() {
        SignActivity entity=new SignActivity();
        return BeanConverUtils.convertBean(signActivityDao.selectOne(entity),SignActivityVo.class);
    }
}
